Chris Pollett > Old Classes >
CS174

( Print View )

Student Corner:
  [Grades Sec1]

  [Submit Sec1]

  [Class Sign Up Sec1]

  [
Lecture Notes]
  [Discussion Board]

Course Info:
  [Texts & Links]
  [Topics/Outcomes]
  [Outcomes Matrix]
  [Grading]
  [HW Info]
  [Exam Info]
  [Regrades]
  [Honesty]
  [Additional Policies]
  [Announcements]

HWs and Quizzes:
  [Hw1]  [Hw2]  [Hw3]
  [Hw4]  [Hw5][Quizzes]

Practice Exams:
  [Mid1]  [Final]

                           












HW#2 --- last modified February 28 2019 22:14:50..

Solution set.

Due date: Sep 30

Files to be submitted:
  Hw2.zip

Purpose: To develop our first PHP project using a model view controller pattern.

Related Course Outcomes:

LO1 -- Write HTML documents containing standard HTML elements including forms, tables, client-side scripts, and server-side scripts.

LO3 -- Write server-side scripts that process HTML forms.

Specification:

For this homework make sure to list both the names and IDs of all group members in a prominent place in what you submit.

Many Women's and Men's magazine contain quizzes for entertainment purposes. For example, Cosmopolitan Magazine currently (Sep 14, 2009) has a quiz on whether your BFF is really on your side. For this homework, you are to create a simple web-site for displaying and tallying such quizzes.

You should organize the files of your project as follows:

  • Project Root/
    • index.php
    • config/
    • controllers/
    • models/
    • views/
    • css/

Access to your site will be through URLs of the form:

BASEURL/index.php?c=controllername&a1=arg1&a2=arg2...
Here BASEURL is the URL for where your site is hosted. Nowhere in your code should you hard code/force the value of this. controllername is the name of the controller requested, it should correspond to the name of a file in the controllers folder. For example, c=foo would say use the file controllers/foo.php as the controller. The name value pairs a1=arg1, etc. correspond to arguments you would like to send to the given controller -- these may or may not be present depending on the controller. On any access to your site, your index.php script should first include any files that it needs from the config folder. This folder should contain as few files as possible. The purpose of these files should be to set up any variables that might need to change if you deployed your program on a different site. The config folder should also have a readme.txt file telling the grader what needs to be changed in config files to get your site running. Be aware that making the grader work too hard to get your site running will result in a lower score.

When a user comes into your site they will probably just come into the page:

BASEURL/
You should treat this as if they used the URL:
BASEURL/index.php?c=default
This controller, after carrying out any initialization needed, should display a view corresponding to a main page where the user can choose among different quizzes to take. On this view, the user should also be able to select to see statistics on other people's quiz response. This view can be stored in the file mainview.php in the views folder.

In addition, to the default controller, you should also have a quiz and statistics controller. The quiz controller uses as its first argument the quiz that is being taken. A quiz might be conducted over several pages, and the second argument to this controller says which page of the quiz one is on. To implement this, depending on the value of the second argument, the quiz controller should display a different view from the views folder. Quizzes should be multiple choice with 1, 2, and 3 as possible choices. As the quiz is being carried out, the quiz controller should update its statistics using the user responses. These statistics should be stored in a file in the models directory. For example, you might use the name quiz1.txt to hold statistics about quiz answers from everyone who took the first quiz. As well as updating overall user statistics, the quiz controller stores the answers a particular participant has made using the $_SESSION superglobal. At the end of the quiz, there should be a final page giving some amusing output concerning how the participant did. So in the case of the BFF quiz mentioned above, it might say the BFF is really a frenemy if the score on the quiz was high. The statistics controller takes as its first argument the name of a quiz. It should then read in the corresponding text file in the models folder and package the information it reads in into an array. This array is then passed to the view which is used to render the quiz statistics (the number of people who chose (1), (2), or (3) for each question on the quiz) in a fabulous format.

The pages on your site should be styled according to stylesheets in your css folder. You should have at least one stylesheet that styles ul tags, styles div tags, and that uses class and id selectors.

Point Breakdown

Folder set-up as described and URLs used as described (1/2pt each)1pt
config directory is used as described and has a readme.txt that is accurate1pt
default controller is as described1pt
mainview.php is as described1pt
quiz controller uses different view file based on second argument1pt
quiz controller updates statistics in model text file according to choice made by a user1pt
quiz controller uses SESSION superglobal as described 1pt
quiz ending is as described1pt
statistics controller as described 1pt
Stylesheets as described 1pt
Total10pts